package com.gdcp.config.shiro;

//import com.gdcp.beans.User;
//import org.apache.shiro.SecurityUtils;
//import org.apache.shiro.authc.*;
//import org.apache.shiro.authz.AuthorizationInfo;
//import org.apache.shiro.authz.SimpleAuthorizationInfo;
//import org.apache.shiro.realm.AuthorizingRealm;
//import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.stereotype.Component;
//import vip.sweet.smile.shiro.pojo.Menu;
//import vip.sweet.smile.shiro.pojo.Role;
//import vip.sweet.smile.shiro.pojo.User;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;


@Component
public class ShiroRealm {
 //   参考https://blog.csdn.net/yywingyy/article/details/99641909
 //extends AuthorizingRealm
/*
    @Override
    public String getName() {
        return "shiroRealm";
    }

    *//**
     * 获取用户权限
     * @param principalCollection
     * @return
     *//*
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        //从shiro中获取user对象
        User user = (User) SecurityUtils.getSubject().getPrincipal();

        // 根据 user对象从数据库中获取用户角色、权限
        SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo();
        //此处 简化查询角色信息(非本文重点) 直接构造角色
        // 获取用户角色集
        List<Role>roleList = new ArrayList<>();
        Role role = new Role();
        role.setRoleName("admin");
        roleList.add(role);
        Set<String> roleSet = roleList.stream().map(Role::getRoleName).collect(Collectors.toSet());
        //设置用户角色  Set<String>
        simpleAuthorizationInfo.setRoles(roleSet);

        // 获取用户权限集
        List<Menu> permissionList = new ArrayList<>();
        Menu update = new Menu();
        update.setMenuId(1L);
        update.setPerms("dept:update");
        permissionList.add(update);

        Menu add = new Menu();
        add.setMenuId(2L);
        add.setPerms("dept:add");
        permissionList.add(add);
        Set<String> permissionSet = permissionList.stream().map(Menu::getPerms).collect(Collectors.toSet());
        //设置用户权限  Set<String>
        simpleAuthorizationInfo.setStringPermissions(permissionSet);
        return simpleAuthorizationInfo;
    }

    *//**
     * 登录验证
     * @param token
     * @return
     * @throws AuthenticationException
     *//*
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        //token中获取用户名密码
        String username = (String) token.getPrincipal();
        String password = new String((char[]) token.getCredentials());
        //从数据库 根据用户名查询 用户信息(非重点略)
        User user = new User();
        user.setUsername(username);
        user.setId(1);
        // 这边如果验证不通过 则可以抛出异常 在登录接口可以捕获
		*//*if(user == null){
			throw new AuthenticationException(“NO_USER”);
		}*//*
        //创建 SimpleAuthenticationInfo会将用户信息放入shiro维护的用户集合
        return new SimpleAuthenticationInfo(user, password, getName());
    }*/
}

